package org.example.tlias.controller;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.annotations.Delete;
import org.example.tlias.annotation.Log;
import org.example.tlias.pojo.Dept;
import org.example.tlias.pojo.Result;
import org.example.tlias.services.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;




@RequestMapping("/depts")
@RestController
@Slf4j
public class DeptController {

//    private static final Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private DeptService deptService;


    @GetMapping
    public Result list(){
//        log.info("查询全部部门信息");
       List<Dept> deptList =  deptService.findAll();
        return Result.success(deptList);
    }

    @Log
    @DeleteMapping
    public Result delete(Integer id){
//        log.info("删除部门信息{}",id);
        deptService.deleteById(id);
        return Result.success();
    }
@Log
    @PostMapping
    public Result save(@RequestBody Dept dept){
//        log.info("新增部门信息");
        deptService.save(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
//        log.info("查询部门信息{}",id);
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }
@Log
    @PutMapping
    public Result update(@RequestBody Dept dept){
//        log.info("修改部门信息{}",dept);
        deptService.update(dept);
        return Result.success();
    }
}
